/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sistemperpustakaan.actionlistener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import javax.swing.JInternalFrame;
import sistemperpustakaan.controller.UserController;
import sistemperpustakaan.view.FrmMain;
import sistemperpustakaan.view.user.FrmUbahPassword;

/**
 *
 * @author EKo
 */
public class ViewUbahPasswordActionListener implements ActionListener {

    FrmMain main;
    UserController controller;

    public ViewUbahPasswordActionListener(FrmMain main) {
        this.main = main;
    }

    public boolean isExists() {
        boolean result = false;
        JInternalFrame[] iFrame = main.getDesktopPane().getAllFrames();
        for (int i = 0; i < iFrame.length; i++) {
            if (iFrame[i].equals(main.getUbahPassword())) {
                result = true;
                break;
            }
        }
        return result;
    }

    public void actionPerformed(ActionEvent e) {
        if (isExists()) {
            try {
                main.getUbahPassword().setSelected(true);
            } catch (PropertyVetoException ex) {
            }
        } else {
            main.setUbahPassword(new FrmUbahPassword(main));
            main.getDesktopPane().add(main.getUbahPassword());
            //try { main.getTipeUserView().setMaximum(true); } catch (PropertyVetoException ex) {  }
            main.getUbahPassword().setVisible(true);
        }
    }
}
